/*
 * Copyright (c) 2007, 2008 Ulrich Hilger, http://dev.uhilger.de, all rights reserved.
 *
 * Published under the terms and conditions of the Apache License 2.0,
 * see http://www.apache.org/licenses/LICENSE-2.0
 */

package de.uhilger.lib.filesystem;

import java.util.EventObject;

/**
 * A class that models events in the Light Development File System
 * 
 * @author Ulrich Hilger, http://dev.uhilger.de
 * @author Published under the terms and conditions of
 * the <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Apache License 2.0</a>
 *
 * @version 2, 11.9.2008
 */
public class FileSystemEvent extends EventObject {
	
	/** event type constant */
	//public static final int FILE_DELETED = 1;
	/** event type constant */
	//public static final int FILE_CREATED = 2;
	/** event type constant */
	//public static final int FILE_RENAMED = 3;
	/** event type constant */
	public static final int PROGRESS = 0;
	/** event type constant */
	public static final int PROCESS_START = 1;
	/** event type constant */
	public static final int PROCESS_END = 2;
	
	/** action type constant */
	public static final int ACTION_COPY = 0;
	/** action type constant */
	public static final int ACTION_RENAME = 1;
	/** action type constant */
	public static final int ACTION_CREATE = 2;
	/** action type constant */
	public static final int ACTION_DELETE = 3;
	/** action type constant */
	public static final int ACTION_IMPORT = 4;
	/** action type constant */
	public static final int ACTION_EXPORT = 5;
	
	private static final String[] actionNames = {"copy", "rename", "create", "delete", "import", 
		"export"}; 

	/** the type of this event */
	private int type;

	/** the action that initiated this event */
	private int eventAction;
	
	/** reference to the files this event messages changes for */
	private FileRef[] files;
	
	/** reference to a value to transport within objects of this event class */
	private Object value;
	
	/**
	 * create a new instance of class FileSystemEvent
	 * @param source  the file system file have changed in
	 * @param action the action that initiated this event, e.g. FileSystemEvent.ACTION_COPY
	 * @param type  the type of event, one of FILE_DELETED, FILE_CREATED and FILE_RENAMED
	 * @param files  the files affected by the change
	 */
	public FileSystemEvent(Object source, int action, int type, FileRef[] files) {
		this(source, action, type, files, null);
	}
	
	/**
	 * create a new instance of class FileSystemEvent
	 * @param source  the file system file have changed in
	 * @param action the action that initiated this event, e.g. FileSystemEvent.ACTION_COPY
	 * @param type  the type of event, one of FILE_DELETED, FILE_CREATED and FILE_RENAMED
	 * @param files  the files affected by the change
	 * @param value  a value to transport wihtin this class
	 */
	public FileSystemEvent(Object source, int action, int type, FileRef[] files, Object value) {
		super(source);
		this.type = type;
		this.files = files;
		this.value = value;
		this.eventAction = action;
	}

	/**
	 * get the type of event
	 * @return  the event type, one of FILE_DELETED, FILE_CREATED and FILE_RENAMED
	 */
	public int getType() {
		return type;
	}
	
	/**
	 * get the action that initiated this event
	 * @return  the action, e.g. FileSystemEvent.ACTION_COPY
	 */
	public int getAction() {
		return eventAction;
	}
	
	/**
	 * get the files that were changed
	 * @return  an array of changed files
	 */
	public FileRef[] getFiles() {
		return files;
	}
	
	/**
	 * get the new value
	 * the FileRef with new file name in case of rename
	 * a progress value as a long in case of progress (not the total processed, only the progress value of this particular event)
	 * @return  the new value
	 */
	public Object getValue() {
		return value;
	}
	
	/**
	 * Get action name for a given action id
	 * @param action  id of action to get name for
	 * @return  action name for goven action id
	 */
	public String getActionName(int action) {
		return actionNames[action];
	}

}
